﻿package mortal.game.view.guild.hintIcon
{
    import Message.Game.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.tools.*;
    import mortal.component.gconst.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class GuildImpeachActionIcon extends ActionBaseIcon
    {
        public var data:SGuildLeaderImpeach;
        private static var _instance:GuildImpeachActionIcon;

        public function GuildImpeachActionIcon()
        {
            super(ResFileConst.guildImpeach);
            if (_instance)
            {
                throw new Error("GuildImpeachActionIcon单例!");
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            NetDispatcher.addCmdListener(ServerCommand.GUILD_IMPEACH_END, this.onImpeachEnd);
            this.data = null;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            NetDispatcher.removeCmdListener(ServerCommand.GUILD_IMPEACH_END, this.onImpeachEnd);
            return;
        }// end function

        override protected function clickHandler(event:MouseEvent) : void
        {
            var onSeclect:Function;
            var onSeclect1:Function;
            var str:String;
            var flags:uint;
            var okEnbel:Boolean;
            var myAlert:GAlertWin;
            var seconds:int;
            var day:int;
            var hours:int;
            var minutes:int;
            var dateStr:String;
            var e:* = event;
            onSeclect = function (param1:int) : void
            {
                myAlert.getButtonByFlag(Alert.OK).enabled = true;
                Alert.okLabel = Alert.okLabelDefault;
                Alert.calcelLabel = Alert.calcelLabelDefault;
                if (param1 == Alert.OK && GuildConst.hasPermissions(GuildConst.AntiImpeach))
                {
                    Alert.show("" + Language.getString(71125), null, Alert.OK | Alert.CANCEL, null, onSeclect1);
                }
                return;
            }// end function
            ;
            onSeclect1 = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    if (GuildConst.hasPermissions(GuildConst.AntiImpeach))
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.GUILD_ANTIIMPEACH));
                    }
                }
                return;
            }// end function
            ;
            super.clickHandler(e);
            if (e.target == this.btn)
            {
                okEnbel;
                if (this.data.impeachType == EGuildLeaderImpeachType._EGuildLeaderImpeachPlayer)
                {
                    str = Language.getStringByParam(71119, this.data.leaderName, this.data.fromPlayer);
                    Alert.okLabel = "" + Language.getString(71120);
                    flags = Alert.OK | Alert.CANCEL;
                    if (!GuildConst.hasPermissions(GuildConst.AntiImpeach))
                    {
                        okEnbel;
                    }
                }
                else if (GuildConst.hasPermissions(GuildConst.AntiImpeach))
                {
                    seconds = DateUtil.getSecondsDis(ClockManager.instance.nowDate, this.data.endDate);
                    day = seconds / (3600 * 24);
                    seconds = seconds - day * (3600 * 24);
                    hours = seconds / 3600;
                    seconds = seconds - hours * 3600;
                    minutes = seconds / 60;
                    dateStr = Language.getStringByParam(71121, day, hours, minutes);
                    str = Language.getStringByParam(71122, dateStr);
                    Alert.okLabel = "" + Language.getString(71120);
                    Alert.calcelLabel = "" + Language.getString(71123);
                    flags = Alert.OK | Alert.CANCEL;
                }
                else
                {
                    str = Language.getStringByParam(71124, this.data.leaderName);
                    flags = Alert.OK;
                }
                myAlert = Alert.show(str, null, flags, null, onSeclect) as GAlertWin;
                myAlert.getButtonByFlag(Alert.OK).enabled = okEnbel;
            }
            return;
        }// end function

        public function onImpeachEnd(param1:Object) : void
        {
            this.hide();
            return;
        }// end function

        public static function get instance() : GuildImpeachActionIcon
        {
            if (!_instance)
            {
                _instance = new GuildImpeachActionIcon;
            }
            return _instance;
        }// end function

    }
}
